#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2025/1/14 19:28
# @Author : ZhengQL


import pytest
from playwright.async_api import async_playwright
import allure
from pytest import Item

@pytest.fixture(scope="session")
async def context_chrome():
    async with async_playwright() as p:
        browser = await p.chromium.launch(headless=False)
        context = await browser.new_context(base_url="http://47.116.12.183")
        yield context
        # 实现用例后置
        await context.close()
        await browser.close()
        await p.stop()


def pytest_runtest_call(item: Item):
    if item.parent.obj.__doc__:
    # 动态添加测试类的 allure.fixture()
        allure.dynamic.feature(item.parent._obj.__doc__)
    # 动态添加测试用例的title标题 allure.title()
    if item.function.__doc__:
        allure.dynamic.title(item.function.__doc__)